package cn.tm.ms.nerver.ft.entry;

/**
 * 模块配置
 * 
 * @author lry
 */
public class ModuleConf {

	//默认的最大重试次数
	public static final int DEFAULT_MAXRETRYNUM=3;
	//默认重试休眠周期,默认不休眠
	public static final long DEFAULT_RETRYCYCLE=10;
	
	//放通率:用于控制后端服务放通的概率,默认1.0表示100%放通,即不做限制
	private double passRate=1.0;
	//最大重试次数
	private int maxRetryNum=0;
	//重试休眠周期,默认不休眠
	private long retryCycle=0;
	//所有容错失败后是否抛异常开关
	private boolean fallbackFEEnable=true;
	
	//mock服务开关
	private boolean mockEnable=false;
	
	
	public ModuleConf() {
	}
	
	/**
	 * @param maxRetryNum 最大重试次数,默认为3次
	 * @param retryCycle 重试休眠周期,默认休眠10ms(强烈不建议设置为0,因为释放句柄资源需要一定的时间)
	 * @param mockEnable mock服务开关,默认为false(关闭)
	 */
	public ModuleConf(int maxRetryNum, long retryCycle, boolean mockEnable){
		this.maxRetryNum=maxRetryNum;
		this.retryCycle=retryCycle;
		this.mockEnable=mockEnable;
	}
	
	
	/**
	 * @param passRate 放通率,默认为1.0(即100%的放通)
	 * @param maxRetryNum 最大重试次数,默认为3次
	 * @param retryCycle 重试休眠周期,默认休眠10ms(强烈不建议设置为0,因为释放句柄资源需要一定的时间)
	 * @param fallbackFEEnable 容错失败是否抛异常开关,默认为true(开启)
	 * @param mockEnable mock服务开关,默认为false(关闭)
	 */
	public ModuleConf(double passRate, int maxRetryNum, long retryCycle, boolean fallbackFEEnable, boolean mockEnable){
		this.passRate=passRate;
		this.maxRetryNum=maxRetryNum;
		this.retryCycle=retryCycle;
		this.fallbackFEEnable=fallbackFEEnable;
		this.mockEnable=mockEnable;
	}

	public double getPassRate() {
		return passRate;
	}

	public void setPassRate(double passRate) {
		this.passRate = passRate;
	}

	public int getMaxRetryNum() {
		return maxRetryNum;
	}

	public void setMaxRetryNum(int maxRetryNum) {
		this.maxRetryNum = maxRetryNum;
	}

	public long getRetryCycle() {
		return retryCycle;
	}

	public void setRetryCycle(long retryCycle) {
		this.retryCycle = retryCycle;
	}

	public boolean isFallbackFEEnable() {
		return fallbackFEEnable;
	}

	public void setFallbackFEEnable(boolean fallbackFEEnable) {
		this.fallbackFEEnable = fallbackFEEnable;
	}

	public boolean isMockEnable() {
		return mockEnable;
	}

	public void setMockEnable(boolean mockEnable) {
		this.mockEnable = mockEnable;
	}

	@Override
	public String toString() {
		return "ModuleConf [passRate=" + passRate + ", maxRetryNum=" + maxRetryNum + ", retryCycle=" 
				+ retryCycle + ", fallbackFEEnable=" + fallbackFEEnable + ", mockEnable=" + mockEnable + "]";
	}
	
}
